package com.honey.feature.sql;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import java.util.regex.Pattern;

/**
 * 使用sql 92的标准注释( "-- " 注释), 
 * @author Administrator
 *
 */
class SqlContent {
	
	private Reader reader;
	
	private static final Pattern regex = Pattern.compile("\\s") ;
	
	public SqlContent(Reader reader ){
		this.reader = reader ;
	}
	
	public  final String getContent() throws IOException{
		StringBuilder answer = new StringBuilder();
		BufferedReader bufferedReader = null;
		if( reader instanceof BufferedReader  ){
			bufferedReader = (BufferedReader) reader;
		}else{
			bufferedReader =new BufferedReader(reader);
		}
		String line = null;
		while( (line = bufferedReader.readLine()) != null){
			line = line.trim();
			if( line.length() >0 ){
				if ( line.length() >=2 && ( ( line.charAt(0) =='-' && line.charAt(1) =='-' ) ||
					 	( line.charAt(0) =='/' && line.charAt(1) =='/' )
					 )
					){
					continue;
				}
				answer.append(line);
			}
		}
		
		return regex.matcher(answer.toString()).replaceAll("");
	}
}
